/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package graphics;

import javax.swing.JOptionPane;
import tools.MessageManager;

/**
 *
 * @author Mattia
 */
public class Login extends javax.swing.JFrame {
    MainFrame x;
    /**
     * Creates new form Login
     */
    public Login(MainFrame x) {
        this.x = x;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        MainPanel = new javax.swing.JLayeredPane();
        Label_Title = new javax.swing.JLabel();
        Username_Label = new javax.swing.JLabel();
        Username_Field = new javax.swing.JTextField();
        Password_Field = new javax.swing.JPasswordField();
        Password_Label = new javax.swing.JLabel();
        MemorizzaCredenziali = new javax.swing.JCheckBox();
        Info = new javax.swing.JTextPane();
        BTN_Login = new javax.swing.JButton();
        Logo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);
        setResizable(false);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
        });

        MainPanel.setBackground(new java.awt.Color(255, 255, 255));
        MainPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        MainPanel.setOpaque(true);
        MainPanel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
        });

        Label_Title.setFont(new java.awt.Font("Honest John's", 0, 48)); // NOI18N
        Label_Title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Label_Title.setText("Amunaptra");
        Label_Title.setBounds(10, 10, 270, 54);
        MainPanel.add(Label_Title, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Username_Label.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        Username_Label.setText("Username");
        Username_Label.setBounds(10, 70, 61, 30);
        MainPanel.add(Username_Label, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Username_Field.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
        });
        Username_Field.setBounds(80, 70, 200, 30);
        MainPanel.add(Username_Field, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Password_Field.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                KeyListner(evt);
            }
        });
        Password_Field.setBounds(80, 110, 200, 30);
        MainPanel.add(Password_Field, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Password_Label.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        Password_Label.setText("Password");
        Password_Label.setBounds(10, 110, 58, 30);
        MainPanel.add(Password_Label, javax.swing.JLayeredPane.DEFAULT_LAYER);

        MemorizzaCredenziali.setBackground(new java.awt.Color(255, 255, 255));
        MemorizzaCredenziali.setText("Memorizza Credenziali");
        MemorizzaCredenziali.setOpaque(false);
        MemorizzaCredenziali.setBounds(10, 143, 270, 20);
        MainPanel.add(MemorizzaCredenziali, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Info.setEditable(false);
        Info.setBorder(null);
        Info.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        Info.setText("Per informazioni circa la registrazione e l'utilizzo dei dati personali visita amunaptra.zagomattia.it");
        Info.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        Info.setEnabled(false);
        Info.setOpaque(false);
        Info.setSelectionColor(new java.awt.Color(255, 255, 255));
        Info.setBounds(10, 170, 130, 70);
        MainPanel.add(Info, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BTN_Login.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        BTN_Login.setText("Login");
        BTN_Login.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_LoginActionPerformed(evt);
            }
        });
        BTN_Login.setBounds(200, 210, 80, 21);
        MainPanel.add(BTN_Login, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Logo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/image/Logo_v3_small.png"))); // NOI18N
        Logo.setVerifyInputWhenFocusTarget(false);
        Logo.setBounds(-10, 100, 300, 140);
        MainPanel.add(Logo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(MainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(MainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BTN_LoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_LoginActionPerformed
        login();
    }//GEN-LAST:event_BTN_LoginActionPerformed

    private boolean checkLogin() {
        String user = "Mattia";
        if(this.Username_Field.getText().equals(user)) {
            return true;
        }
        return false;
    }
    
    private void login() {
        if(checkLogin()) {
            dispose();
            x.setLocationRelativeTo(null);
            x.setVisible(true);
        } else {
            MessageManager.generic(this,"Username e/o password errati!", "Login Errato", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private void KeyListner(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_KeyListner
        
        switch(evt.getKeyCode()) {
            case java.awt.event.KeyEvent.VK_ENTER: login(); break;
            case java.awt.event.KeyEvent.VK_ESCAPE: System.exit(0); break;    
        }
    }//GEN-LAST:event_KeyListner

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTN_Login;
    private javax.swing.JTextPane Info;
    private javax.swing.JLabel Label_Title;
    private javax.swing.JLabel Logo;
    private javax.swing.JLayeredPane MainPanel;
    private javax.swing.JCheckBox MemorizzaCredenziali;
    private javax.swing.JPasswordField Password_Field;
    private javax.swing.JLabel Password_Label;
    private javax.swing.JTextField Username_Field;
    private javax.swing.JLabel Username_Label;
    // End of variables declaration//GEN-END:variables
}
